const publicStyle = { style: { width: "180px" } }
// 普通查询表单配置
export const fieldList = ref([
  {
    field: "skuRange",
    placeholder: "可批量搜索",
    type: "textarea",
    style: { width: "200px" },
    select: [
      { label: "SKU", value: "sku" },
      { label: "自定SKU", value: "custom_sku" },
      { label: "商品名称", value: "sku_title" },
    ],
  },
  {
    field: "asin",
    placeholder: "ASIN",
    type: "textarea",
    style: { width: "200px" },
  },
  {
    field: "site_id",
    type: "select",
    originField: "amazonSite",
    enumOriginField: true, // 获取枚举接口不同
    multiple: true,
    collapseTags: true,
    options: { placeholder: "国家" },
    ...publicStyle,
  },
  {
    field: "stocking_status",
    type: "select",
    originField: "Plan.PlanStockingAnalysis.StockingStatusEnum",
    options: { placeholder: "备货状态" },
    style: { width: "200px" },
  },
  {
    field: "stocking_quantity",
    label: "需求数量",
    type: "numberRange",
    style: { width: "200px" },
  },

  {
    field: "confirm_status",
    type: "select",
    originField: "Plan.PlanStockingAnalysis.ConfirmStatusEnum",
    options: { placeholder: "确认状态" },
  },
  {
    field: "show_type",
    type: "select",
    options: {
      placeholder: "显示导入销量预测数据",
      data: [
        { label: "显示近五个月导入或者有库存的", value: "0" },
        { label: "只显示近五个月导入", value: "1" },
        { label: "只显示库存大于0", value: "2" },
      ],
    },
    style: { width: "200px" },
  },
])

// 高级查询表单配置
export const highFieldList = ref([
  {
    field: "sales_status",
    type: "select",
    multiple: true,
    collapseTags: true,
    originField: "sku_status",
    enumOriginField: true, // 获取枚举接口不同
    options: { placeholder: "商品状态" },
  },
  {
    field: "supply_status",
    type: "select",
    multiple: true,
    collapseTags: true,
    originField: "sku_resource_status",
    enumOriginField: true, // 获取枚举接口不同
    options: {
      placeholder: "货源状态",
    },
  },
  // {
  //   field: "active_status",
  //   type: "select",
  //   originField: "goods_active",
  //   enumOriginField: true, // 获取枚举接口不同
  //   options: {
  //     placeholder: "商品活跃度",
  //   },
  // },
  {
    field: "activity_status",
    type: "select",
    multiple: true,
    collapseTags: true,
    originField: "Base.BaseAsinList.ActivityStatusEnum",
    options: {
      placeholder: "商品活跃度",
    },
  },

  {
    field: "is_requires_stocking",
    type: "select",
    originField: "Base.BaseAsinList.IsRequiresStockingEnum",
    options: { placeholder: "是否备料" },
  },
  {
    field: "planner_user",
    type: "cascaderNew",
    placeholder: "计划人员",

    // style: { width: "100%" },
  },

  {
    field: "operator_user",
    type: "cascaderNew",
    placeholder: "运营人员",
    style: { width: "100%" },
  },
  {
    field: "purchaser_user",
    type: "cascaderNew",
    placeholder: "采购人员",
    style: { width: "100%" },
  },
  {
    field: "purchase_days",
    // label: "采购天数",
    prepend: "采购天数",
    type: "numberRange",
  },
  {
    field: "transportation_days",
    prepend: "运输天数",
    type: "numberRange",
  },
  {
    field: "safety_days",
    prepend: "安全天数",
    type: "numberRange",
  },
  {
    field: "fba_sellable",
    prepend: "可用库存",
    type: "numberRange",
  },
  {
    field: "procurement_in_transit",
    prepend: "采购在途",
    type: "numberRange",
  },
  {
    field: "fba_in_transit",
    prepend: "头程在途",
    type: "numberRange",
  },
  {
    field: "transportation_type",
    type: "select",
    multiple: true,
    collapseTags: true,
    originField: "Base.BaseAsinList.TransportationTypeEnum",
    options: {
      placeholder: "运输类型",
    },
  },
  {
    field: "supplier_code",
    placeholder: "供应商编码",
    type: "textarea",
  },

  // {
  //   field: "supplier_code",
  //   type: "selectV2",
  //   originField: "supplierCode",
  //   enumOriginField: true, // 获取枚举接口不同
  //   itemProps: {
  //     placeholder: "供应商编码",
  //     multiple: true,
  //     collapseTags: true,
  //     props: {
  //       label: "supplier_code",
  //       value: "supplier_code",
  //     },
  //   },
  //   options: { data: [] },
  //   style: { width: "100%" },
  // },
  // {
  //   field: "supplier_id",
  //   type: "selectV2",
  //   originField: "supplier",
  //   enumOriginField: true, // 获取枚举接口不同
  //   itemProps: {
  //     placeholder: "供应商ID",
  //     multiple: true,
  //     collapseTags: true,
  //     props: {
  //       label: "supplier_code",
  //       value: "supplier_code",
  //     },
  //   },
  //   options: { data: [] },
  //   style: { width: "100%" },
  // },

  {
    field: "is_prepared_material",
    type: "select",
    originField: "Plan.PlanStockingAnalysis.PreparedMaterialEnum",
    options: {
      placeholder: "备料库存是否充足",
    },
  },

  {
    field: "estimated_difference",
    type: "select",
    originField: "Base.BaseAsinList.EstimatedDifferenceEnum",
    options: { placeholder: "销售预估差异" },
  },

  {
    field: "store_id",
    type: "select",
    originField: "shopOpt",
    multiple: true,
    collapseTags: true,
    enumOriginField: true, // 获取枚举接口不同
    options: { placeholder: "Asin店铺" },
    style: { width: "100%" },
  },
])
const countTimeKey = [
  "procurement_processing_days",
  "procurement_days",
  "local_warehouse_processing_days",
  "transportation_days",
  "overseas_transit_warehouse_processing_days",
  "platform_listing_days",
  "safety_days",
  "procurement_frequency",
]
const countTime = (form) => {
  form.basic_lead_time = eval(countTimeKey.map((k) => Number(form?.[k])).join("+"))
}
export const batchOConfig = reactive({
  // 基础LT天数设置
  base_lt_days: {
    formOptions: { inline: true, labelPosition: "top", labelWidth: "200" },
    width: 720,
    title: "基础LT天数设置",
    form: {},
    fieldOptions: [
      {
        field: "basic_lead_time",
        // label: "基础LT天数",
        slot: "ltDay",
        style: { width: "100%" },
      },
      {
        field: "procurement_processing_days",
        label: "采购处理天数",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "procurement_days",
        label: "采购天数",
        append: "AppendDay",
        disabled: true,
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "local_warehouse_processing_days",
        label: "本地仓处理天数",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "transportation_type",
        label: "运输类型",
        type: "select",
        originField: "Base.BaseAsinList.TransportationTypeEnum",
        style: { width: "200px" },
        options: { placeholder: "运输类型" },
      },
      {
        field: "transportation_days",
        label: "运输天数",
        append: "AppendDay",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "overseas_transit_warehouse_processing_days",
        label: "海外中转仓处理天",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "platform_listing_days",
        label: "平台上架天数",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "safety_days",
        label: "安全天数",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
      {
        field: "procurement_frequency",
        label: "采购频次",
        append: "AppendDay",
        onBlur: (e, form) => countTime(form),
        style: { width: "200px" },
      },
    ],
    tips: "基础LT天数 = 采购处理天数 + 采购天数 + 本地仓处理天数 + 运输天数 + 海外中转仓处理天数 + 平台上架天数 + 安全天数；",
  },
  // 批量设置备货参数
  lt_days: {
    title: "批量设置备货参数",
    formOptions: { inline: true, labelPosition: "top" },
    fieldOptions: [
      {
        field: "transportation_days",
        label: "备货天数",
        append: "AppendDay",
        style: { width: "200px" },
      },
      {
        field: "procurement_processing_days",
        label: "采购处理天数",
        append: "AppendDay",
        style: { width: "200px" },
      },
      // {
      //   field: "procurement_days",
      //   label: "采购天数",
      //   append: "AppendDay",
      //   disabled: true,
      //   style: { width: "200px" },
      // },
      {
        field: "local_warehouse_processing_days",
        label: "本地仓处理天数",
        append: "AppendDay",
        style: { width: "200px" },
      },
      {
        field: "overseas_transit_warehouse_processing_days",
        label: "海外中转仓处理天数",
        append: "AppendDay",
        style: { width: "200px" },
      },
      {
        field: "platform_listing_days",
        label: "平台上架天数",
        append: "AppendDay",
        style: { width: "200px" },
      },
      {
        field: "safety_days",
        label: "安全天数",
        append: "AppendDay",
        style: { width: "200px" },
      },
      {
        field: "procurement_frequency",
        label: "采购频次",
        append: "AppendDay",
        style: { width: "200px" },
      },
    ],
    tips: "数据为空时，系统默认过滤，不更新覆盖；\n数据不为空时，系统更新数据，下次统计时生效！",
  },
  // 批量设置备货状态
  stocking_status: {
    title: "批量设置备货状态",
    formOptions: { labelPosition: "top" },
    fieldOptions: [
      {
        field: "stocking_status",
        label: "备货状态",
        type: "select",
        originField: "Plan.PlanStockingAnalysis.StockingStatusEnum",
        options: {
          placeholder: "备货状态",
        },
        style: { width: "200px" },
      },
      {
        field: "stocking_remark",
        label: "备注信息",
        type: "textarea",
        style: { width: "320pz" },
        autosize: { minRows: 4, maxRows: 6 },
      },
    ],
    tips: "暂时不备货：下周一重置，重新计算是否需要备货",
  },
  // 修改库存信息
  overseas: {
    title: "修改库存信息",
    formOptions: { inline: true, labelPosition: "top" },
    fieldOptions: [
      { field: "overseas_warehouse_available", label: "海外仓可用", style: { width: "200px" } },
      { field: "fba_available", label: "FBA可用", style: { width: "200px" } },
      { field: "overseas_warehouse_in_transit", label: "海外仓在途", style: { width: "200px" } },
      { field: "fba_in_transit", label: "FBA在途", style: { width: "200px" } },
    ],
    rules: {
      overseas_warehouse_available: [{ required: true, message: "请输入海外仓可用", trigger: "blur" }],
      fba_available: [{ required: true, message: "请输入FBA可用", trigger: "blur" }],
      overseas_warehouse_in_transit: [{ required: true, message: "请输入海外仓在途", trigger: "blur" }],
      fba_in_transit: [{ required: true, message: "请输入FBA在途", trigger: "blur" }],
    },
  },
})

// 操作
export const handleFunctions = ref({})

// 弹窗表格详情弹窗配置
export const dialogTabelInfoConfig = {
  // 历史采购订单价格
  historyPurchase: {
    title: "历史采购订单价格",
    width: "1200",
    info: {},
    infoColumn: [
      { label: "sku", value: "sku" },
      { label: "产品名称", value: "sku_name" },
    ],
    tableOptions: {
      border: true,
      columns: [
        { field: "purchase_no", title: "采购单号" },
        { field: "supplier_name", title: "供应商" },
        {
          title: "下单价",
          width: "80",
          slots: {
            default: ({ row }) => <VText value={row.is_drawback == 1 ? row.unit_price : row.unit_price_tax} line={1} />,
          },
        },
        { field: "purchase_num", title: "下单数量", width: "80" },
        { field: "unit_price_tax", title: "开票税点", width: "80" },
        { field: "unit_price_tax", title: "含税价", width: "80" },
        { field: "unit_tracking_price", title: "单个运费", width: "80" },
        {
          // field: "unit_purchase_price",
          title: "单个采购成本",
          width: "110",
          slots: {
            default: ({ row }) => <VText value={row.is_drawback == 1 ? row.unit_purchase_price : row.unit_purchase_price_tax} line={1} />,
          },
        },
        {
          title: "下单人员\n采购时间",
          slots: {
            default: ({ row }) => (
              <div>
                <VText value={row.create_user} line={1} />
                <VText value={row.create_time} line={1} />
              </div>
            ),
          },
        },
        { field: "purchase_date", title: "采购耗时" },
      ],
      data: [],
    },
  },

  // 运营预测日均销量
  forecastSales: {
    title: "运营预测日均销量",
    tableOptions: {
      border: true,
      rowConfig: {
        height: 140,
      },
      columns: [
        {
          title: "产品信息",
          width: "150",
          slots: {
            default: ({ row }) => (
              <div>
                <VText title="SKU" value={row.sku} line={1} type="link" />
                <VText title="自定义" value={row.custom_sku} line={1} />
                <VText title="ASIN" value={row.asin} line={1} />
                <VText title="国家" value={row.site_code} line={1} />
                <VText title="活跃度" value={row.activity_status} line={1} />
              </div>
            ),
          },
        },
        {
          title: "基础LT天数",
          width: "150",
          slots: {
            default: ({ row }) => (
              <div>
                <div class="text-[18px] text-[#3487ff]">{row?.plan_lt_days?.basic_lead_time}天</div>
                <VText title="采购天数" value={String(row.plan_lt_days.procurement_days) ? row.plan_lt_days.procurement_days + "天" : ""} line={1} />
                <VText title="运输天数" value={String(row.plan_lt_days.transportation_days) ? row.plan_lt_days.transportation_days + "天" : ""} line={1} />
                <VText title="安全天数" value={row.plan_lt_days.safety_days ? row.plan_lt_days.safety_days + "天" : ""} line={1} />
              </div>
            ),
          },
        },
      ],
      data: [],
    },
    tips: "<span class='text-[16px] text-[#333]'>运营预测日均销量</span> = LT天数内运营预测的总销量和 / LT天数 = XX \n \n 备注：根据运营提供的未来几个月的销量预测和基础LT天数，每天定时计算LT天数内的运营预测日均销量",
    dayColumns: {
      title: "",
      width: "150",
      isType: "month",
      slots: {
        default: ({ row, column }) => (
          <div>
            <VText title="日常" value={row?.[column.title]?.daily_sales} line={1} />
            <VText title="活动" value={row?.[column.title]?.activity_sales} line={1} />
            <VText title="总销量" value={row?.[column.title]?.total_sales} line={1} />
            <VText title="实际销量" value={row?.[column.title]?.actual_sales} line={1} />
          </div>
        ),
      },
    },
  },
  // 待下PO明细
  purchaseDemandSku: {
    title: "待下PO明细",
    width: "1200",
    info: {},
    infoColumn: [
      { label: "sku", value: "sku" },
      { label: "ASIN", value: "asin" },
    ],
    tableOptions: {
      border: true,
      columns: [
        { field: "demand_type_name", title: "类型" },
        { field: "demand_no", title: "单据" },
        { field: "audit_time.end", title: "审核通过时间", width: "140" },
        { field: "demand_status_name", title: "状态" },
        { field: "demand_time", title: "需求日期", width: "140" },
        { field: "demand_num", title: "需求数", width: "80" },
        {
          field: "leave_num",
          title: "待下PO数",
          width: "240",
          slots: {
            default: ({ row }) => (
              <div>
                {row.leave_data.map((v, i) => (
                  <div class="grid grid-cols-2">
                    <VText title="sku" value={v.sku} line={1} />
                    <VText title="数量" value={v.leave_num} line={1} />
                  </div>
                ))}
              </div>
            ),
          },
        },
        //

        { field: "create_time", title: "更新时间", width: "180" },
      ],
      data: [],
    },
  },
  // 待下PO明细
  purchaseDemandSkuNo: {
    title: "已下PR未完结明细",
    width: "1200",
    info: {},
    infoColumn: [
      { label: "sku", value: "sku" },
      { label: "ASIN", value: "asin" },
    ],
    tableOptions: {
      border: true,
      columns: [
        { field: "demand_type_name", title: "类型" },
        { field: "demand_no", title: "单据" },
        { field: "audit_time", title: "审核通过时间", width: "140" },
        { field: "plan_order_status_name", title: "状态" },
        { field: "demand_time", title: "需求日期", width: "140" },
        { field: "demand_num", title: "需求数", width: "80" },
        {
          field: "leave_num",
          title: "未生成发货计划数",
          width: "140",
          slots: { default: ({ row }) => <div>{row.demand_num - row.plan_order_num}</div> },
        },
        { field: "create_time", title: "更新时间", width: "180" },
        {
          title: "操作",
          width: "190",
          slots: {
            default: ({ row }) => (
              <div>
                <span class="text-[#3487ff] cursor-pointer" onClick={() => handleFunctions?.value?.deliverPlan(row)}>
                  生成发货计划
                </span>
                <span class="text-[#3487ff] cursor-pointer ml-[8px]" onClick={() => handleFunctions?.value?.onUpdate(row)}>
                  变更
                </span>
              </div>
            ),
          },
        },
      ],
      data: [],
    },
  },
}
